package io;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class OswDemo {
    public static void main(String[] args) throws Exception {
        FileOutputStream fos = new FileOutputStream("osw.txt",true);
        OutputStreamWriter osw = new OutputStreamWriter(fos,StandardCharsets.UTF_8);
        Scanner scanner = new Scanner(System.in);
        System.out.println("已打开记事本");
        while (true){
            System.out.println("请写入");
            String sr = scanner.nextLine();
            if ("exit".equalsIgnoreCase(sr)){
                System.out.println("写入完毕");
                break;
            }
//            byte [] bt = sr.getBytes(StandardCharsets.UTF_8);
//            fos.write(bt);
            osw.write(sr);
            //osw.write("\\s");
            osw.flush();

        }
        osw.close();
    }
}
